home *** CD-ROM | disk | FTP | other *** search
- Path: apoll.informatik.uni-bonn.de!zeus!schregle
- From: schregle@zeus.informatik.uni-bonn.de (Roland Schregle)
- Newsgroups: comp.lang.c++
- Subject: Re: Virtual Base Class
- Date: 11 Mar 1996 16:27:14 GMT
- Organization: Universit"at Bonn, Informatik Abt. II, R"omerstr. 164, 53117 Bonn
- Message-ID: <4i1k92$3n8@apoll.informatik.uni-bonn.de>
- References: <313F98D0.102E@ucla.edu>
- NNTP-Posting-Host: zeus.informatik.uni-bonn.de
- X-Newsreader: TIN [version 1.2 PL2]
-
- Dennis Rahaman (dennisr@ucla.edu) wrote:
- : This is what I want to do:
-
- : a
- : / \
- : b c
- : \ /
- : d
-
-
- : class a
- : {
- : //...
- : };
-
- : class b : public virtual a
- : {
- : //...
- : };
-
- : class c : public virtual b
- : {
- : //...
- : };
-
- : class d : public b, public c
- : {
- : //...
- : };
-
-
- : void f ()
- : {
- : a a1;
- : d* pd = (d*) &a1; // error: can't cast virtual base to derived
- : }
-
- : ///////////////////////////////////////////////////////////
- : Can someone explain why I can't cast a virtual base class to a derived
- : class?
-
- : What should I do instead?
-
- : Any help would be appreciated.
-
-
-
- I have the same problem! Somebody suggested the following (in terms of the
- above egg sample):
-
- void f()
- {
- a a1;
- d* pd = (d*)(void*)&a1;
- }
-
- I haven't tried this yet. C'mon you C++ cracks out there!!! :)
-
-
- GanjaTron
-